package com.atguigu.spring5.testdemo;

import com.atguigu.spring5.config.SpringConfig;
import com.atguigu.spring5.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpring5Demo1 {


    @Test
    public void testService1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");

        UserService userService = context.getBean("userService", UserService.class);
        System.out.println(userService);
        userService.add();

    }


    @Test
    public void testService2() {

        //java类的配置形式
        //加载java配置类
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);


//        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");

        UserService userService = applicationContext.getBean("userService", UserService.class);
        System.out.println(userService);
        userService.add();

    }

}
